package com.maodou.android.ui.page.detail

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.maodou.android.ui.page.DetailKey
import com.maodou.core.navigation.GlobalUiBus
import com.maodou.core.navigation.Navigator3
import com.maodou.core.navigation.NavigationAnimation
import com.maodou.core.navigation.DialogStyle

@Composable
fun DetailScreen(key: DetailKey) {
    val title = key.title
    val id = key.id

    Column(Modifier.padding(16.dp)) {
        Text(text = "Detail Page")
        Spacer(Modifier.height(8.dp))
        Text(text = "title = $title")
        Text(text = "id = $id")
        Spacer(Modifier.height(16.dp))
        
        // 展示不同的返回动画效果
        Text(text = "返回动画示例：")
        Spacer(Modifier.height(8.dp))
        Row {
            Button(onClick = { Navigator3.pop(NavigationAnimation.SLIDE) }) { 
                Text("Slide Back") 
            }
            Spacer(Modifier.width(8.dp))
            Button(onClick = { Navigator3.pop(NavigationAnimation.FADE) }) { 
                Text("Fade Back") 
            }
        }
        Spacer(Modifier.height(8.dp))
        Row {
            Button(onClick = { Navigator3.pop(NavigationAnimation.SCALE) }) { 
                Text("Scale Back") 
            }
            Spacer(Modifier.width(8.dp))
            Button(onClick = { Navigator3.pop(NavigationAnimation.NONE) }) { 
                Text("No Anim Back") 
            }
        }
        Spacer(modifier = Modifier.height(20.dp))
        Button(onClick = {
            GlobalUiBus.showPopup(
                style = DialogStyle.Center,
                content = {
                    Text("弹框内容", modifier = Modifier.clickable {  })
                }
            )
        }) { Text("打开弹框") }
    }
}

// 兼容旧版基于 NavController 的导航注册：从 backStackEntry 读取参数并委托到 Nav3 版本